/*	Copyright (c) 2010 MIEM (http://miem.edu.ru/)
 *
 *	Authors:
 *		* Andrey Shtykovskiy    ( ashty@itas.miem.edu.ru      )
 *		* Edward Klyshinsky     ( klyshinsky@itas.miem.edu.ru )
 *		* Sergey R. Tumkovsky   ( srt@itas.miem.edu.ru        )
 *
 *	This file is part of MOAN (morphology analysis) software.
 *
 *	MOAN is free software: you can redistribute it and/or modify it 
 *	under the terms of the GNU General Public License as published 
 *	by the Free Software Foundation, either version 3 of the License, 
 *	or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License 
 *	along with MOAN. If not, see http://www.gnu.org/licenses/.
 */



#ifndef __PARAMETER_HPP_GUARD__
#define __PARAMETER_HPP_GUARD__

#include <stdint.h>

#include "..\..\src\moan\bit_rake.hpp"

namespace moan {

	class parameter {

	public:
		typedef uint64_t value_type;
		typedef bit_rake<value_type> parameter_type;

		parameter() : _p(0) { }
		explicit parameter(const parameter_type& p) : _p(p) { }
		explicit parameter(value_type v) {
			_p.from_value(v);
		}

		inline parameter_type&
		value() {
			return _p;
		}

		inline const parameter_type&
		get() const {
			return _p;
		}

		inline bool 
		operator== (const parameter& p) const {
			return ( _p.value() == p.get().value() );
		}


		inline bool
		equals(const parameter& p, size_t id) const {
			return _p.extract(id) == p.get().extract(id);
		}

		inline bool
		equals(const parameter& p, size_t id_begin, size_t id_end) const {
			return _p.extract(id_begin, id_end) == p.get().extract(id_begin, id_end);
		}

		template< typename iter >
		bool 
		equals(const parameter& p, iter& begin, const iter& end ) const {
			assert( begin < end );

			parameter_type::value_type v1 = 0, v2 = 0;

			for(; begin != end; ++begin ) {
				v1 |= _p.extract(*begin);
				v2 |= p.get().extract(*begin);
			}

			return v1 == v2;
		}

	private:
		bit_rake<uint64_t> _p;
	};

} /* namespace moan */

#endif /* __PARAMETER_HPP_GUARD__ */